﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Configuration;

namespace GetNetcardInfo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
        private void ShowAdapterInfo()  
        {  
            NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();  
            richTextBox1.AppendText("适配器个数：" + adapters.Length);
             
            int index = 0;  
  
            foreach (NetworkInterface adapter in adapters)  
            {  
                index++;  
                //显示网络适配器描述信息、名称、类型、速度、MAC 地址  
                lst_NetworkAdapter.Items.Add("---------------------第" + index + "个适配器信息---------------------");  
                lst_NetworkAdapter.Items.Add("描述信息：" + adapter.Name);  
                lst_NetworkAdapter.Items.Add("类型：" + adapter.NetworkInterfaceType);  
                lst_NetworkAdapter.Items.Add("速度：" + adapter.Speed / 1000 / 1000 + "MB");  
                lst_NetworkAdapter.Items.Add("MAC 地址：" + adapter.GetPhysicalAddress());  
                  
                //获取IPInterfaceProperties实例  
                IPInterfaceProperties adapterProperties = adapter.GetIPProperties();  
                  
                //获取并显示DNS服务器IP地址信息  
                IPAddressCollection dnsServers = adapterProperties.DnsAddresses;  
                if (dnsServers.Count > 0)  
                {  
                    foreach (IPAddress dns in dnsServers)  
                    {  
                        lst_NetworkAdapter.Items.Add("DNS 服务器IP地址：" + dns + "\n");  
                    }  
                }  
                else  
                {  
                    lst_NetworkAdapter.Items.Add("DNS 服务器IP地址：" + "\n");  
                }  
            }  
    }
}
